{% extends 'base.html' %}

{% block title %}标签: {{ tag.name }} - Will's Blog{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-8">
        <h1 class="mb-4">标签: {{ tag.name }}</h1>
        
        {% if posts.items %}
            {% for post in posts.items %}
                <div class="card mb-4">
                    {% if post.featured_image %}
                        <img src="{{ post.featured_image }}" class="card-img-top" alt="{{ post.title }}">
                    {% endif %}
                    <div class="card-body">
                        <h2 class="card-title">{{ post.title }}</h2>
                        <p class="card-text text-muted">
                            <small>
                                <i class="bi bi-person"></i> {{ post.author.username }} | 
                                <i class="bi bi-calendar"></i> {{ post.created.strftime('%Y-%m-%d') }} | 
                                <i class="bi bi-eye"></i> {{ post.views }} 次阅读
                            </small>
                        </p>
                        <p class="card-text">{{ post.summary }}</p>
                        <a href="{{ url_for('main.post', slug=post.slug) }}" class="btn btn-primary">阅读更多</a>
                    </div>
                    <div class="card-footer text-muted">
                        {% if post.tags %}
                            <i class="bi bi-tags"></i> 
                            {% for tag in post.tags %}
                                <a href="{{ url_for('main.tag', slug=tag.slug) }}" class="badge bg-secondary text-decoration-none">{{ tag.name }}</a>
                            {% endfor %}
                        {% endif %}
                    </div>
                </div>
            {% endfor %}
            
            <!-- 分页 -->
            {% if posts.pages > 1 %}
                <nav aria-label="Page navigation">
                    <ul class="pagination justify-content-center">
                        {% if posts.has_prev %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for('main.tag', slug=tag.slug, page=posts.prev_num) }}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li class="page-item disabled">
                                <a class="page-link" href="#" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        {% endif %}
                        
                        {% for page in range(1, posts.pages + 1) %}
                            {% if page == posts.page %}
                                <li class="page-item active">
                                    <a class="page-link" href="{{ url_for('main.tag', slug=tag.slug, page=page) }}">{{ page }}</a>
                                </li>
                            {% else %}
                                <li class="page-item">
                                    <a class="page-link" href="{{ url_for('main.tag', slug=tag.slug, page=page) }}">{{ page }}</a>
                                </li>
                            {% endif %}
                        {% endfor %}
                        
                        {% if posts.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for('main.tag', slug=tag.slug, page=posts.next_num) }}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li class="page-item disabled">
                                <a class="page-link" href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% endif %}
                    </ul>
                </nav>
            {% endif %}
        {% else %}
            <div class="alert alert-info">
                该标签下暂无文章。
            </div>
        {% endif %}
    </div>
    
    <div class="col-md-4">
        <div class="card mb-4">
            <div class="card-header">所有标签</div>
            <div class="card-body">
                <div class="tags-cloud">
                    {% for other_tag in tags %}
                        <a href="{{ url_for('main.tag', slug=other_tag.slug) }}" 
                           class="badge {% if other_tag.id == tag.id %}bg-primary{% else %}bg-secondary{% endif %} text-decoration-none m-1">
                            {{ other_tag.name }}
                        </a>
                    {% endfor %}
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">关于博客</div>
            <div class="card-body">
                <p>欢迎来到我的个人博客，这里记录了我的学习、思考和生活。</p>
                <a href="{{ url_for('main.about') }}" class="btn btn-outline-primary">了解更多</a>
            </div>
        </div>
    </div>
</div>
{% endblock %}